function hot_cai() {
	热菜.sort(function (x, y) {
		return Number(x.价格[0].原价 - x.价格[0].特价) - Number(y.价格[0].原价 - y.价格[0].特价)
	})
	document.getElementById("re").innerHTML = "";
	for (var a = 0; a < 热菜.length; a++) {
		var hot_原价 = 热菜[a].价格[0].原价;
		var hot_特价 = 热菜[a].价格[0].特价;
		var li = document.createElement("div");
		li.classList = 'menu';
		li.innerHTML =
			"<a href='JavaScript:;' class='num'>" + Number(a + 1) + "/" + 热菜.length + "  " + "</a>" +
			"<img src='" + 热菜[a].img + "' alt=''/>" +
			"<a href='JavaScript:;' class = 'dish'>" + 热菜[a].name + "</a>" +
			"<div class='xiangqing'>" + 热菜[a].详情 + "</div>" +
			"<a href='JavaScript:;' class='yuanjia'>原价:" + hot_原价 + " 元</a>" +
			"<a href='JavaScript:;' class='xianjia'>标价:" + Number(hot_原价 - hot_特价) + " 元</a>" +
			"<a href='JavaScript:;' class='youhui'>优惠:" + hot_特价 + " 元</a>" +
			"<button class='" + 热菜[a].购买按钮 + "'>点菜: ¥ " + Number(hot_原价 - hot_特价) + "</button>" +
			"<div class='gmcg'>" + 热菜[a].购买返回 + "</div>";
		document.getElementById("re").appendChild(li);
	}
	// $(".neirong .menu").draggable();
}
function cool_cai() {
	凉菜.sort(function (x, y) {
		return Number(x.价格[0].原价 - x.价格[0].特价) - Number(y.价格[0].原价 - y.价格[0].特价)
	})
	document.getElementById("liang").innerHTML = "";
	for (var a = 0; a < 凉菜.length; a++) {
		var cool_原价 = 凉菜[a].价格[0].原价;
		var cool_特价 = 凉菜[a].价格[0].特价;
		var li = document.createElement("div");
		li.classList = 'menu';
		li.innerHTML =
			"<a href='JavaScript:;' class='num'>" + Number(a + 1) + "/" + 凉菜.length + "  " + "</a>" +
			"<img src='" + 凉菜[a].img + "' alt=''/>" +
			"<a href='JavaScript:;' class = 'dish'>" + 凉菜[a].name + "</a>" +
			"<div class='xiangqing'>" + 凉菜[a].详情 + "</div>" +
			"<a href='JavaScript:;' class='yuanjia'>原价:" + cool_原价 + " 元</a>" +
			"<a href='JavaScript:;' class='xianjia' >标价:" + Number(cool_原价 - cool_特价) + " 元</a>" +
			"<a href='JavaScript:;' class='youhui'>优惠:" + cool_特价 + " 元</a>" +
			"<button class='" + 凉菜[a].购买按钮 + "'>点菜: ¥ " + Number(cool_原价 - cool_特价) + "</button>" +
			"<div class='gmcg'>" + 凉菜[a].购买返回 + "</div>";
		document.getElementById("liang").appendChild(li);
	}
	// $(".neirong .menu").draggable();
}

function tang_cai() {
	汤.sort(function (x, y) {
		return Number(x.价格[0].原价 - x.价格[0].特价) - Number(y.价格[0].原价 - y.价格[0].特价)
	})
	document.getElementById("tang2").innerHTML = "";
	for (var a = 0; a < 汤.length; a++) {
		var tang_原价 = 汤[a].价格[0].原价;
		var tang_特价 = 汤[a].价格[0].特价;
		var li = document.createElement("div");
		li.classList = 'menu';
		li.innerHTML =
			"<a href='JavaScript:;' class='num'>" + Number(a + 1) + "/" + 汤.length + "  " + "</a>" +
			"<img src='" + 汤[a].img + "' alt=''/>" +
			"<a href='JavaScript:;' class = 'dish'>" + 汤[a].name + "</a>" +
			"<div class='xiangqing'>" + 汤[a].详情 + "</div>" +
			"<a href='JavaScript:;' class='yuanjia'>原价:" + tang_原价 + " 元</a>" +
			"<a href='JavaScript:;' class='xianjia' >标价:" + Number(tang_原价 - tang_特价) + " 元</a>" +
			"<a href='JavaScript:;' class='youhui'>优惠:" + tang_特价 + " 元</a>" +
			"<button class='" + 汤[a].购买按钮 + "'>点菜: ¥ " + Number(tang_原价 - tang_特价) + "</button>" +
			"<div class='gmcg'>" + 汤[a].购买返回 + "</div>";
		document.getElementById("tang2").appendChild(li);
	}
	// $(".neirong .menu").draggable();
}

function zhu_cai() {
	主食.sort(function (x, y) {
		return Number(x.价格[0].原价 - x.价格[0].特价) - Number(y.价格[0].原价 - y.价格[0].特价)
	})
	document.getElementById("zhu").innerHTML = "";
	for (var a = 0; a < 主食.length; a++) {
		var zhu_原价 = 主食[a].价格[0].原价;
		var zhu_特价 = 主食[a].价格[0].特价;
		var li = document.createElement("div");
		li.classList = 'menu';
		li.innerHTML =
			"<a href='JavaScript:;' class='num'>" + Number(a + 1) + "/" + 主食.length + "  " + "</a>" +
			"<img src='" + 主食[a].img + "' alt=''/>" +
			"<a href='JavaScript:;' class = 'dish'>" + 主食[a].name + "</a>" +
			"<div class='xiangqing'>" + 主食[a].详情 + "</div>" +
			"<a href='JavaScript:;' class='yuanjia'>原价:" + zhu_原价 + " 元</a>" +
			"<a href='JavaScript:;' class='xianjia' >标价:" + Number(zhu_原价 - zhu_特价) + " 元</a>" +
			"<a href='JavaScript:;' class='youhui'>优惠:" + zhu_特价 + " 元</a>" +
			"<button class='" + 主食[a].购买按钮 + "'>点菜: ¥ " + Number(zhu_原价 - zhu_特价) + "</button>" +
			"<div class='gmcg'>" + 主食[a].购买返回 + "</div>";
		document.getElementById("zhu").appendChild(li);
	}
	// $(".neirong .menu").draggable();
}

function yan_cai() {
	香烟.sort(function (x, y) {
		return Number(x.价格[0].原价 - x.价格[0].特价) - Number(y.价格[0].原价 - y.价格[0].特价)
	})
	document.getElementById("yan").innerHTML = "";
	for (var a = 0; a < 香烟.length; a++) {
		var yan_原价 = 香烟[a].价格[0].原价;
		var yan_特价 = 香烟[a].价格[0].特价;
		var li = document.createElement("div");
		li.classList = 'menu';
		li.innerHTML =
			"<a href='JavaScript:;' class='num'>" + Number(a + 1) + "/" + 香烟.length + "  " + "</a>" +
			"<img src='" + 香烟[a].img + "' alt=''/>" +
			"<a href='JavaScript:;' class = 'dish'>" + 香烟[a].name + "</a>" +
			"<div class='xiangqing'>" + 香烟[a].详情 + "</div>" +
			"<a href='JavaScript:;' class='yuanjia'>原价:" + yan_原价 + " 元</a>" +
			"<a href='JavaScript:;' class='xianjia' >标价:" + Number(yan_原价 - yan_特价) + " 元</a>" +
			"<a href='JavaScript:;' class='youhui'>优惠:" + yan_特价 + " 元</a>" +
			"<button class='" + 香烟[a].购买按钮 + "'>点菜: ¥ " + Number(yan_原价 - yan_特价) + "</button>" +
			"<div class='gmcg'>" + 香烟[a].购买返回 + "</div>";
		document.getElementById("yan").appendChild(li);
	}
	// $(".neirong .menu").draggable();
}

function jiu_cai() {
	酒水.sort(function (x, y) {
		return Number(x.价格[0].原价 - x.价格[0].特价) - Number(y.价格[0].原价 - y.价格[0].特价)
	})
	document.getElementById("jiu").innerHTML = "";
	for (var a = 0; a < 酒水.length; a++) {
		var jiu_原价 = 酒水[a].价格[0].原价;
		var jiu_特价 = 酒水[a].价格[0].特价;
		var li = document.createElement("div");
		li.classList = 'menu';
		li.innerHTML =
			"<a href='JavaScript:;' class='num'>" + Number(a + 1) + "/" + 酒水.length + "  " + "</a>" +
			"<img src='" + 酒水[a].img + "' alt=''/>" +
			"<a href='JavaScript:;' class = 'dish'>" + 酒水[a].name + "</a>" +
			"<div class='xiangqing'>" + 酒水[a].详情 + "</div>" +
			"<a href='JavaScript:;' class='yuanjia'>原价:" + jiu_原价 + " 元</a>" +
			"<a href='JavaScript:;' class='xianjia' >标价:" + Number(jiu_原价 - jiu_特价) + " 元</a>" +
			"<a href='JavaScript:;' class='youhui'>优惠:" + jiu_特价 + " 元</a>" +
			"<button class='" + 酒水[a].购买按钮 + "'>点菜: ¥ " + Number(jiu_原价 - jiu_特价) + "</button>" +
			"<div class='gmcg'>" + 酒水[a].购买返回 + "</div>";
		document.getElementById("jiu").appendChild(li);
	}
	// $(".neirong .menu").draggable();
}

function weekly_report() {
	for (let a in 周记) {
		var div = document.createElement("div");
		div.classList = "diary";
		div.innerHTML =
			"<p>" + 周记[a].周 + "</p>" +
			"<p>" + 周记[a].日期 + "</p>" +
			"<font>" + 周记[a].内容 + "</font>";
		document.getElementById('diary').appendChild(div);
	}
}
const 购买2 = [].reverse(); //购物车
const 等你的一句晚安 = [];
const 我将玫瑰藏于身后 = [];
const 明年花还会再开吗 = [];
const 夜萤火虫和你 = [];
var 发放优惠券 = 0;
var 一元优惠券 = 10;
var 使用一元优惠券 = 0;
var total = 0; //结账
//钱包
var 感谢您曾经来过 = Infinity;
// for (let g = 1; g <= 1; g++) {
// 	感谢您曾经来过 = 感谢您曾经来过 * 1000000000000000;
// }
//函数
//此函数用于使用优惠券的加减及显示
function lingqu() {
	document.getElementById("一元优惠券").innerHTML = "当前 1 ¥ 优惠券剩余:  " + (++一元优惠券) + " 张";
	document.getElementById("领取一元").innerHTML = "领取 1 ¥ 优惠券 当前还可领取:  " + (--发放优惠券) + " 张";
}

function shiyong() {
	document.getElementById("正在使用").innerHTML = '正在使用 1 ¥ 优惠券:  ' + (++使用一元优惠券) + ' 张';
	document.getElementById('一元优惠券').innerHTML = '当前 1 ¥ 优惠券剩余:  ' + (--一元优惠券) + ' 张';
}
//180秒之后重新获取
var interval;
var count = 180;
var curCount = count;
function sendMessage() {
	if (curCount != count) {
		//
	} else {
		curCount = count;
		document.getElementById("btnSendCode").setAttribute("disabled", "true");
		msg = curCount + "秒后重获";
		document.getElementById("btnSendCode").value = msg;
		document.getElementById("btnsendcode2").innerHTML = "获得卡密成功 " + curCount + " 秒后重获";
		interval = window.setInterval(setRemainTime, 1000);
	}
}

function setRemainTime() {
	if (curCount == 1) {
		curCount = count;
		window.clearInterval(interval);
		document.getElementById("btnSendCode").removeAttribute("disabled");
		document.getElementById("btnSendCode").value = "获取卡密";
		document.getElementById("btnsendcode2").innerHTML = "点击上方按钮可获得卡密";
	} else {
		curCount--;
		document.getElementById("btnSendCode").setAttribute("disabled", "true");
		document.getElementById("btnSendCode").value = curCount + "秒后重获";
		document.getElementById("btnsendcode2").innerHTML = "获得卡密成功 " + curCount + " 秒后重获";
	}
}

function xskami() { //显示卡密
	document.getElementById('card').innerHTML = '';
	for (a = 0; a < 等你的一句晚安.length; a++) {
		var li = document.createElement("div");
		li.classList = "km";
		li.innerHTML =
			"<textarea>" + 等你的一句晚安[a] + "</textarea>" +
			"<input type='button' class='kami'>";
		document.getElementById('card').appendChild(li);
		$(".kami").val("使用卡密");
	}
}
// for循环语句
var classxuanze;
var htmlneirong;

function forxunhuan() {
	for (var b = 0; b < 热菜.length; b++) {
		if (热菜[b].name == caiming) {
			$("#re .gmcg").eq(b).html("<a href='JavaScript:;' class='" + classxuanze + "'>" + htmlneirong + "</a>");
			$("#re button").eq(b).prop("class", "buy");
			热菜[b].购买按钮 = "buy";
			热菜[b].购买返回 = "<a href='JavaScript:;' class='" + classxuanze + "'>" + htmlneirong + "</a>";
		}
	}
	for (var b = 0; b < 凉菜.length; b++) {
		if (caiming == 凉菜[b].name) {
			$("#liang .gmcg").eq(b).html("<a href='JavaScript:;' class='" + classxuanze + "'>" + htmlneirong + "</a>");
			$("#liang button").eq(b).prop("class", "buy");
			凉菜[b].购买按钮 = "buy";
			凉菜[b].购买返回 = "<a href='JavaScript:;' class='" + classxuanze + "'>" + htmlneirong + "</a>";
		}
	}
	for (var b = 0; b < 汤.length; b++) {
		if (caiming == 汤[b].name) {
			$("#tang2 .gmcg").eq(b).html("<a href='JavaScript:;' class='" + classxuanze + "'>" + htmlneirong + "</a>");
			$("#tang2 button").eq(b).prop("class", "buy");
			汤[b].购买按钮 = "buy";
			汤[b].购买返回 = "<a href='JavaScript:;' class='" + classxuanze + "'>" + htmlneirong + "</a>";
		}
	}
	for (var b = 0; b < 主食.length; b++) {
		if (caiming == 主食[b].name) {
			$("#zhu .gmcg").eq(b).html("<a href='JavaScript:;' class='" + classxuanze + "'>" + htmlneirong + "</a>");
			$("#zhu button").eq(b).prop("class", "buy");
			主食[b].购买按钮 = "buy";
			主食[b].购买返回 = "<a href='JavaScript:;' class='" + classxuanze + "'>" + htmlneirong + "</a>";
		}
	}
	for (var b = 0; b < 香烟.length; b++) {
		if (caiming == 香烟[b].name) {
			$("#yan .gmcg").eq(b).html("<a href='JavaScript:;' class='" + classxuanze + "'>" + htmlneirong + "</a>");
			$("#yan button").eq(b).prop("class", "buy");
			香烟[b].购买按钮 = "buy";
			香烟[b].购买返回 = "<a href='JavaScript:;' class='" + classxuanze + "'>" + htmlneirong + "</a>";
		}
	}
	for (var b = 0; b < 酒水.length; b++) {
		if (caiming == 酒水[b].name) {
			$("#jiu .gmcg").eq(b).html("<a href='JavaScript:;' class='" + classxuanze + "'>" + htmlneirong + "</a>");
			$("#jiu button").eq(b).prop("class", "buy");
			酒水[b].购买按钮 = "buy";
			酒水[b].购买返回 = "<a href='JavaScript:;' class='" + classxuanze + "'>" + htmlneirong + "</a>";
		}
	}
}

function tanchukuang() {
	document.getElementById("tooltip").innerHTML = "";
	var li = document.createElement("div");
	li.innerHTML = "<a href='JavaScript:;' id='none'>X</a>" +
		"<div id='name'>请核对账单</div>" +
		"<p id='jiesuan1'>是否对菜单结算,总价: " + total + " ¥</p>" +
		"<p>其中优惠券:- " + 使用一元优惠券 + " ¥</p>" +
		"<p id='shifu1'>实付: " + Number(total - 使用一元优惠券) + " ¥</p>" +
		"<div id='dishname'></div>" +
		"<button id='yes' class='yes'>确定</button>" +
		"<button id='no' class='no'>取消</button>";
	document.getElementById("tooltip").appendChild(li);
	var hello = [];
	for (let i = 0; i < 购买2.length; i++) {
		hello +=
			"<li>" +
			"<a href='JavaScript:;' class='name'>" + Number(i + 1) + ". " + 购买2[i].name + "</a>" +
			"<a href='JavaScript:;' class='danjia'>单价: " + 购买2[i].单价 + " ￥</a>" +
			"<a href='JavaScript:;' class='value'>数量: " + 购买2[i].值 + "</a>" +
			"<a href='JavaScript:;' class='yingfu'>共计: " + Number(购买2[i].值 * 购买2[i].单价) + " ￥</a>" +
			"</li>";
	}
	$("#dishname").html('<ul>' + hello + '</ ul>');
	hello = "";
}
// var tooltip_ul_li = 0;
// $(document).on("click", "#tooltip ul li", function () {
// 	let a = $("#tooltip ul li").index(this);
// 	tooltip_ul_li = a;
// 	let X = event.pageX - 50;
// 	let Y = event.pageY - 20;
// 	$("#yjcd").show();
// 	$("#yjcdinfo").css("top", Y);
// 	$("#yjcdinfo").css("left", X);
// 	window.onload = tanchukuang();
// })
// $(document).on("click", "#yjcd", function () {
// 	$("#yjcd").hide();
// 	window.onload = tanchukuang();
// })
// $(document).on("click", "#sc", function () {
// 	// e.stopPropagation();
// 	购买2.splice(tooltip_ul_li, 1);
// 	$("#yjcd").hide();
// 	window.onload = tanchukuang();
// 	window.onload = xsgm();
// })
var chenggong = 3;
var chenggongjishi;
var jishiqi;
var goumaijieguo;
var alert1 = 0;
function tckUI() {
	$("#chenggong").lbyl({
		content: goumaijieguo + " -- " + chenggongjishi + "秒后自动关闭",
		speed: 0,
		fadeSpeed: 250,
		hovertreeColors: ["#fff"],
		type: 'fade',
	})
}
function tck() {
	let tckcolor = [
		"#52d24189",
		"rgba(0, 255, 149, 0.463)",
		"rgba(200, 0, 255, 0.463)",
		"rgba(255, 155, 85, 0.463)",
		"rgba(140, 0, 255, 0.463)",
		"rgba(0, 255, 0, 0.563)",
		"#00ffff7c",
		"#F660AB7c",
		"#FF00FF7c",
		"#8E35EF7c",
	];
	window.clearInterval(jishiqi);
	chenggongjishi = chenggong;
	$("#chenggong").fadeIn();
	let suiji = Math.floor(Math.random() * tckcolor.length);
	$("#chenggong").css("background-color", tckcolor[suiji]);
	// $("#chenggong").html(goumaijieguo + " -- " + chenggongjishi + "秒后自动关闭");
	window.onload = tckUI();
	jishiqi = window.setInterval(chenggong3, 1000);
}
function chenggong2() {
	goumaijieguo = 时间2 + " " + goumaijieguo;
	夜萤火虫和你.push(goumaijieguo);
	$("#lsjl").html("点击查看部分历史记录 当前有 " + 夜萤火虫和你.length + " 个记录");
	if (alert1 == 0) {
		window.onload = tck();
		$("#small").html("");
	} else if (alert1 == 1) {
		$("#small").lbyl({
			content: goumaijieguo.substring(20),
			speed: 50,
			hovertreeColors: ['deeppink', 'blue', "#d241c1", "#D24161"],
			type: 'fade',
		})
	} else {
		alert1 = 0;
		window.onload = tck();
		$("#small").html("");
	}
}

function chenggong3() {
	if (chenggongjishi == 1) {
		$("#chenggong").fadeOut();
		$("#chenggong").html(begin);
		goumaijieguo = begin;
		window.clearInterval(jishiqi);
	} else {
		chenggongjishi--;
		$("#chenggong").fadeIn();
		// $("#chenggong").html(goumaijieguo + " -- " + chenggongjishi + "秒后自动关闭");
		window.onload = tckUI();
	}
}
var queren;
var leibie;
$(document).on("click", "#tooltip #yes", function () {
	let zz = /^\d+(\.\d+)?$/;
	if (zz.test(total)) {
		if (购买2.length > 0) {
			if (感谢您曾经来过 >= Number(total - Number(1 * 使用一元优惠券))) {
				qrgm[0].yingfu = Number(total - 使用一元优惠券);
				$("#tooltip").fadeOut();
				$("#password").html("");
				let li = document.createElement("div");
				li.innerHTML =
					"<div id='quxiao' title='取消购买'>&times;</div>" +
					"<font id='jine'></font>" +
					"<font id='srmima'>请输入密码</font>" +
					"<input type='password' id='srpassword' maxlength='12'/>" +
					"<div id='qrpassword'>确认</div>" +
					"<font id='yzpassword2' style='color:red;'>密码长度应为6-12个字符</font>";
				document.getElementById("password").appendChild(li);
				$("#jine").html("¥ " + qrgm[0].yingfu);
				$("#password").fadeIn();
			} else {
				goumaijieguo = "钱包金额不足";
				window.onload = chenggong2();
			}
		} else {
			goumaijieguo = "未购买商品";
			window.onload = chenggong2();
		}
	} else {
		goumaijieguo = "购物车内商品单价或购买数量发生错误,请检查后再次进行购买";
		window.onload = chenggong2();
	}
})
$(document).on("click", "#tooltip #none", function () {
	$("#tooltip").fadeOut();
	$(".shadow3").fadeOut();
	$("#tooltip").html(begin3);
})
$(document).on("click", "#tooltip #no", function () {
	$("#tooltip").fadeOut();
	$("#tooltip").html(begin3);
	$(".shadow3").fadeOut();
})
$(document).on("click", "#qrpassword", function () {
	if ($("#srpassword").val().length < 6 || $("#srpassword").val().length > 12) {
		goumaijieguo = "密码长度应为6~12个字符";
		window.onload = chenggong2();
	} else {
		var password2 = str_md5(b64_md5(hex_md5(document.getElementById("srpassword").value)));
		if (qrgm[0].password == "") {
			goumaijieguo = "您还未进行登录";
			window.onload = chenggong2();
		} else if (password2 != qrgm[0].password) {
			goumaijieguo = "密码错误请重新填写";
			window.onload = chenggong2();
		} else {
			// 购买记录
			let ul = document.createElement("ul");
			ul.innerHTML = "<a href='JavaScript:;'>时间: " + 时间 + "</a>" +
				"<a href='JavaScript:;' class='zongjia'>合计: " + total + " ¥</a>" +
				"<a href='JavaScript:;' class='danjia'>单价:(¥)</a>" +
				"<a href='JavaScript:;' class='shuliang'>数量:(份/瓶)</a>" +
				"<a href='JavaScript:;' class='yingfu'>共:(¥)</a>";
			document.getElementById("record").appendChild(ul)
			for (let o = 0; o < 购买2.length; o++) {
				let li = document.createElement("li");
				li.innerHTML =
					购买2[o].name +
					"<a href='JavaScript:;' class='danjia'>" + 购买2[o].单价 + "</a>" +
					"<a href='JavaScript:;' class='shuliang'>" + 购买2[o].值 + "</a>" +
					"<a href='JavaScript:;' class='yingfu'>" + Number(购买2[o].单价 * 购买2[o].值) + "</a>" +
					"<a href='JavaScript:;' class='qxgm'>" + "取消购买" + "</a>";
				ul.appendChild(li)
			}
			// for
			//购买完成时
			$("#tooltip").fadeOut();
			$(".shadow3").fadeOut();
			$("#password").fadeOut();
			$("#password").html("");
			for (var gm = 0; gm < 购买2.length; gm++) {
				caiming = 购买2[gm].name;
				classxuanze = "yifukuan";
				htmlneirong = "已购买";
				window.onload = forxunhuan();
			}
			购买2.splice(0, 购买2.length);
			感谢您曾经来过 = 感谢您曾经来过 - Number(total - Number(1 * 使用一元优惠券));
			document.getElementById("goumai").innerHTML = 购买2;
			goumaijieguo = "付款成功,共计: " + Number(total - Number(1 * 使用一元优惠券)) + " ¥";
			window.onload = chenggong2();
			console.log("付款成功,共计: " + Number(total - Number(1 * 使用一元优惠券)) + " ¥");
			使用一元优惠券 = 0;
			document.getElementById("正在使用").innerHTML = "正在使用一元优惠券:  " + 使用一元优惠券 + " 张";
			$("#password").html(begin2);
		}
	}
})
var total_price;

function tanchukuang2() {
	document.getElementById("tooltip").innerHTML = "";
	var li = document.createElement("div");
	li.innerHTML = "<a href='JavaScript:;' id='none'>X</a>" +
		"<div id='name'>味道小厨●中餐厅</div>" +
		"<p id='general'>是否对菜单结算,总价: " + 购买2[total_price].应付 + " ¥</p>" +
		"<p>其中优惠券:- " + 使用一元优惠券 + " ¥</p>" +
		"<p id='close_an_account'>实付: " + Number(购买2[total_price].应付 - 使用一元优惠券) + " ¥</p>" +
		"<div id='dishname'>点击查看菜单</div>" +
		"<button id='ok' class='yes'>确定</button>" +
		"<button id='no' class='no'>取消</button>";
	document.getElementById("tooltip").appendChild(li);
	$("#dishname").html("<ul>" +
		"<li>" +
		"<a href='JavaScript:;' class='name'>" + 购买2[total_price].name + "</a>" +
		"<a href='JavaScript:;' class='danjia'>单价: " + 购买2[total_price].单价 + " ￥</a>" +
		"<a href='JavaScript:;' class='value'>数量: " + 购买2[total_price].值 + "</a>" +
		"<a href='JavaScript:;' class='yingfu'>共计: " + 购买2[total_price].应付 + " ￥</a>" +
		"</li></ ul>");
}
$(document).on("click", "#ok", function () {
	var 价格 = Number((购买2[total_price].单价 * 购买2[total_price].值) - 使用一元优惠券);
	if (total <= 使用一元优惠券) {
		goumaijieguo = "优惠金额大于或等于应付金额,点击正在使用一元优惠券可减去优惠券";
		window.onload = chenggong2();
	} else {
		if (感谢您曾经来过 >= Number(价格)) {
			使用一元优惠券 = 0;
			var 感谢您曾经来过2 = Number(感谢您曾经来过 - (价格));
			感谢您曾经来过 = 感谢您曾经来过2;
			document.getElementById("正在使用").innerHTML = "正在使用一元优惠券:  " + 使用一元优惠券 + " 张";
			// 购买记录
			let ul = document.createElement("ul");
			ul.innerHTML = "<a href='JavaScript:;'>时间: " + 时间 + "</a>" +
				"<a href='JavaScript:;' class='zongjia'>合计: " + Number(购买2[total_price].单价 * 购买2[total_price].值) + " ¥</a>" +
				"<a href='JavaScript:;' class='danjia'>单价:(¥)</a>" +
				"<a href='JavaScript:;' class='shuliang'>数量:(份/瓶)</a>" +
				"<a href='JavaScript:;' class='yingfu'>共:(¥)</a>";
			document.getElementById("record").appendChild(ul)
			let li = document.createElement("li");
			li.innerHTML = "<li>" + 购买2[total_price].name +
				"<a href='JavaScript:;' class='danjia'>" + 购买2[total_price].单价 + "</a>" +
				"<a href='JavaScript:;' class='shuliang'>" + 购买2[total_price].值 + "</a>" +
				"<a href='JavaScript:;' class='yingfu'>" + Number(购买2[total_price].单价 * 购买2[total_price].值) + "</a>" +
				"<a href='JavaScript:;' class='qxgm'>" + "取消购买" + "</a>" +
				"</li>";
			ul.appendChild(li)
			//购买后
			$("#tooltip").fadeOut();
			$(".shadow3").fadeOut();
			classxuanze = "yifukuan";
			htmlneirong = "已购买";
			caiming = 购买2[total_price].name;
			window.onload = forxunhuan();
			购买2.splice(total_price, 1);
			goumaijieguo = "付款成功,共计: " + Number(价格) + " ¥";
			window.onload = chenggong2();
			console.log("付款成功,共计: " + Number(价格) + " ¥");
			window.onload = xsgm();
		} else {
			goumaijieguo = "钱包金额不足";;
			window.onload = chenggong2();
		}
	}
})

function chakan() {
	$("#chakan").fadeOut();
	$("#chakan2").attr("src", "");
	$("#src").html(begin4);
	$(".shadow4").fadeOut();
	$("body").css("overflow-y", "");
}
//判断图片是否损坏
function CheckImgExists(imgurl) {
	var ImgObj = new Image(); //判断图片是否存在  
	ImgObj.src = imgurl;
	//没有图片，则返回-1  
	if (ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) {
		return true;
	} else {
		return false;
	}
}
const tupiansunhuai = "图片损坏 原因 : 图片被修改或未加入图片";
function xsgm() {
	document.getElementById("goumai").innerHTML = "";
	for (var aa = 0; aa < 购买2.length; aa++) {
		var li2 = document.createElement("div");
		li2.classList = "buy2";
		li2.innerHTML =
			// "<div class='fuxuankuang'><input type='checkbox' name='checkboxs'></div>" +
			"<a href='JavaScript:;' class='num'>" + Number(aa + 1) + ". </a>" +
			"<a href='JavaScript:;' class='dish'>" + 购买2[aa].name + "</a>" +
			"<img src='" + 购买2[aa].img + "' alt=''/>" +
			"<div class='xiangqing'>" + 购买2[aa].详情 + "</div>" +
			"<input type='button' value='-' class='subtract'>" +
			"<input type='text' value='" + 购买2[aa].值 + "' class='text'>" +
			"<span class='tishi'>格式正确</span>" +
			"<input type='button' value='+' class='plus'>" +
			"<a href='JavaScript:;' class='xianjia' >单价:" + 购买2[aa].单价 + " 元</a>" +
			"<button class='total_price'>单独购买: " + Number(购买2[aa].单价 * 购买2[aa].值) + "</button>" +
			"<a href=JavaScript:; class='splice'>删除</a>" + "<br/>";
		document.getElementById("goumai").appendChild(li2);
		document.querySelectorAll(".fuxuankuang input").checkbox = true;
	}
	// $("#goumai .buy2").draggable();
}

$(function () {
	$("#fan").click(function () {
		window.onload = chakan();
	})
	$(document).on("click", ".show img", function () {
		let a = $(".show img").index(this);
		let name = $(".show .dish").eq(a).html();
		let aa = $(".show img").eq(a).attr("src"); //获取点击图片的地址
		$("#weihu").css("overflow-y", "hidden");
		$(".shadow4").fadeIn();
		$("#chakan").fadeIn();
		$("#chakan2").attr("src", aa); //呈现图片至#chakan2
		$("#src").html("商品: <a href='JavaScript:;' style='color:red;'>" + name + "</a> 图片仅供参考");
	})
	$(document).on("click", ".show .dish", function () {
		let a = $(".show .dish").index(this);
		let name = $(".show .dish").eq(a).html();
		let aa = $(".show img").eq(a).attr("src"); //获取点击图片的地址
		$("#weihu").css("overflow-y", "hidden");
		$(".shadow4").fadeIn();
		$("#chakan").fadeIn();
		$("#chakan2").attr("src", aa); //呈现图片至#chakan2
		$("#src").html("商品: <a href='JavaScript:;' style='color:red;'>" + name + "</a> 图片仅供参考");
	})
	$("#fan").html("&times;");
	$("#fan").attr("title", "关闭");
	$("#chakan2").attr("alt", "");
	$("#chakan2").attr("title", "点击图片可放大查看");
	$(document).on("click", "#chakan2", function () {
		var src = $("#chakan2").attr('src');
		if (CheckImgExists(src) == false) {
			goumaijieguo = tupiansunhuai;
			window.onload = chenggong2();
		} else if (CheckImgExists(src) == true) {
			window.open(src);
			window.onload = chakan();
		} else {
			goumaijieguo = "未知错误 -- 打开图片时遇到问题";
			window.onload = chenggong2();
		}
	})
	$('#btnSendCode').click(function () {
		if (curCount != count) {
			goumaijieguo = "请稍等一下,等时间结束再点击吧~";
			window.onload = chenggong2();
		} else {
			var kami = "味道小厨·旗舰店-" + hex_md5(时间);
			等你的一句晚安[等你的一句晚安.length] = kami;
			我将玫瑰藏于身后[我将玫瑰藏于身后.length] = hex_md5(kami);
			window.onload = xskami();
			goumaijieguo = "获得卡密成功";
			window.onload = chenggong2();
		}
	})
	$(document).on("click", "#card .km .kami", function () {
		var a = $("#card .km .kami").index(this);
		var b = $("#card .km textarea").eq(a).val();
		var c = 等你的一句晚安[a];
		var d = 我将玫瑰藏于身后[a];
		if (b == c && hex_md5(b) == d) {
			等你的一句晚安.splice(a, 1);
			我将玫瑰藏于身后.splice(a, 1);
			window.onload = xskami();
			document.getElementById("领取一元").innerHTML = "当前 1 ¥ 优惠券剩余:  " + (++发放优惠券) + " 张";
			goumaijieguo = "使用成功";
			window.onload = chenggong2();
		} else {
			goumaijieguo = "卡密错误,请检查卡密格式或内容是否正确";
			window.onload = chenggong2();
		}
	})
	document.getElementById("领取一元").innerHTML = "领取 1 ¥ 优惠券 当前还可领取: " + 发放优惠券 + " 张";
	document.getElementById("使用一元").innerHTML = "使用 1 ¥ 优惠券";
	document.getElementById("正在使用").innerHTML = "正在使用 1 ¥ 优惠券:  " + 使用一元优惠券 + " 张";
	document.getElementById("一元优惠券").innerHTML = "当前 1 ¥ 优惠券剩余:   " + 一元优惠券 + " 张";
	$("#领取一元").click(function () {
		if (发放优惠券 > 0) {
			window.onload = lingqu();
		} else {
			goumaijieguo = "优惠券被领完了";
			window.onload = chenggong2();
		}
	})
	$("#使用一元").click(function () {
		if (total >= 20 && total < 50) {
			if (使用一元优惠券 >= 1) {
				goumaijieguo = "20¥ ~ 49¥ 单次优惠券最高可使用1张";
				window.onload = chenggong2();
			} else if (一元优惠券 > 0) {
				window.onload = shiyong();
			} else { }
		} else if (total >= 50 && total < 100) {
			if (使用一元优惠券 >= 3) {
				goumaijieguo = "50¥~90¥单次优惠券最高可使用3张";
				window.onload = chenggong2();
			} else if (一元优惠券 > 0) {
				window.onload = shiyong();
			} else { }
		} else if (total >= 100) {
			if (使用一元优惠券 >= 5) {
				goumaijieguo = "大于 100¥ 单次优惠券最高可使用5张";
				window.onload = chenggong2();
			} else if (一元优惠券 > 0) {
				window.onload = shiyong();
			} else { }
		} else {
			goumaijieguo = "单次消费 20 ¥以上方可使用优惠券";
			window.onload = chenggong2();
		}
	})
	$("#正在使用").click(function () {
		if (使用一元优惠券 > 0) {
			document.getElementById("正在使用").innerHTML = "正在使用 1 ¥ 优惠券:  " + (--使用一元优惠券) + " 张";
			document.getElementById("一元优惠券").innerHTML = "当前 1 ¥ 优惠券剩余:  " + (++一元优惠券) + " 张";
		} else {
			goumaijieguo = "正在使用的优惠券清除完毕";
			window.onload = chenggong2();
		}
	})
	$("#gm").click(function () {
		if (购买2.length <= 0) {
			goumaijieguo = "未购买商品";
			window.onload = chenggong2();
		} else {
			$("#tooltip").fadeIn();
			$(".shadow3").fadeIn();
			window.onload = tanchukuang();
		}
	})
	//单独购买
	$(document).on("click", ".total_price", function () {
		// total_price = $(".total_price").index(this);
		// $("#tooltip").fadeIn();
		// $(".shadow3").fadeIn();
		// goumaijieguo =  "您已打开购买页面,点击页面外任意位置可取消购买";
		// window.onload = chenggong2();
		// window.onload = tanchukuang2();
		// goumaijieguo = "当前功能正在维护中";
		// window.onload = chenggong2();
	})
	//获取页面的每个按钮
	var btns = document.getElementsByClassName("btn") //获取内容盒子
	var contents = document.getElementsByClassName("content")
	//遍历每个按钮为其添加点击事件
	for (var i = 0; i < btns.length; i++) {
		btns[i].index = i;
		btns[i].onclick = function () { //对当前点击的按钮赋予active类名及显示当前按钮对应的内容
			for (var j = 0; j < btns.length; j++) {
				btns[j].className = btns[j].className.replace(' active', '').trim();
				contents[j].className = contents[j].className.replace(' show', '').trim();
			}
			this.className = this.className + ' active';
			contents[this.index].className = contents[this.index].className + ' show';
		};
	}
	// weekly_report();
	//菜谱内容显示
	window.onload = hot_cai();
	window.onload = cool_cai();
	window.onload = tang_cai();
	window.onload = zhu_cai();
	window.onload = yan_cai();
	window.onload = jiu_cai();
	// 给元素添加标签
	document.getElementById("explain2").className = 'neirong content';
	document.getElementById('re').className = 'neirong content show';
	document.getElementById('liang').className = 'neirong content';
	document.getElementById('tang2').className = 'neirong content';
	document.getElementById('zhu').className = 'neirong content';
	document.getElementById('yan').className = 'neirong content';
	document.getElementById('jiu').className = 'neirong content';
	document.getElementById('one').className = 'neirong2 content';
	document.getElementById('diary').className = 'neirong content';
	document.getElementById('card').className = 'neirong content';
	document.getElementById('record').className = 'neirong content';
	$('#re').on('click', '.buy', function () {
		var a = $('#re button').index(this);
		if (热菜[a].购买按钮 == "buy") {
			var hot_原价 = 热菜[a].价格[0].原价;
			var hot_特价 = 热菜[a].价格[0].特价;
			购买2.push({
				'name': 热菜[a].name,
				'img': 热菜[a].img,
				'值': '1',
				'详情': 热菜[a].详情,
				'单价': Number(hot_原价 - hot_特价),
			});
			$("#re .gmcg").eq(a).html("<a href='JavaScript:;' class='yigoumai'>已添加到[购物车]</a>");
			$("#re button").eq(a).prop("class", "yidianji");
			热菜[a].购买按钮 = "yidianji";
			热菜[a].购买返回 = "<a href='JavaScript:;' class='yigoumai'>已添加到[购物车]</a>";
			goumaijieguo = 热菜[a].name + " 可在 [购物车] 内进行付款";
			window.onload = chenggong2();
			window.onload = xsgm();
		} else {
			goumaijieguo = 热菜[a].name + " 已经在购物车了";
			chenggong2();
			$("#re button").eq(a).prop("class", "yidianji");
		}
	});
	$('#liang').on('click', '.buy', function () {
		var a = $('#liang button').index(this);
		if (凉菜[a].购买按钮 == "buy") {
			var cool_原价 = 凉菜[a].价格[0].原价;
			var cool_特价 = 凉菜[a].价格[0].特价;
			购买2.push({
				'name': 凉菜[a].name,
				'img': 凉菜[a].img,
				'值': '1',
				'详情': 凉菜[a].详情,
				'单价': Number(cool_原价 - cool_特价),
			});
			$("#liang .gmcg").eq(a).html("<a href='JavaScript:;' class='yigoumai'>已添加到[购物车]</a>");
			$("#liang button").eq(a).prop("class", "yidianji");
			凉菜[a].购买按钮 = "yidianji";
			凉菜[a].购买返回 = "<a href='JavaScript:;' class='yigoumai'>已添加到[购物车]</a>";
			goumaijieguo = 凉菜[a].name + " 可在 [购物车] 内进行付款";
			window.onload = chenggong2();
			window.onload = xsgm();
		} else {
			goumaijieguo = 凉菜[a].name + " 已经在购物车了";
			chenggong2();
			$("#liang button").eq(a).prop("class", "yidianji");
		}
	});
	$('#tang2').on('click', '.buy', function () {
		var a = $('#tang2 button').index(this);
		if (汤[a].购买按钮 == 'buy') {
			var tang_原价 = 汤[a].价格[0].原价;
			var tang_特价 = 汤[a].价格[0].特价;
			购买2.push({
				'name': 汤[a].name,
				'img': 汤[a].img,
				'值': '1',
				'详情': 汤[a].详情,
				'单价': Number(tang_原价 - tang_特价),
			});
			$("#tang2 .gmcg").eq(a).html("<a href='JavaScript:;' class='yigoumai'>已添加到[购物车]</a>");
			$("#tang2 button").eq(a).prop("class", "yidianji");
			汤[a].购买按钮 = "yidianji";
			汤[a].购买返回 = "<a href='JavaScript:;' class='yigoumai'>已添加到[购物车]</a>";
			goumaijieguo = 汤[a].name + " 可在 [购物车] 内进行付款";
			window.onload = chenggong2();
			window.onload = xsgm();
		} else {
			goumaijieguo = 汤[a].name + " 已经在购物车了";
			chenggong2();
			$("#tang2 button").eq(a).prop("class", "yidianji");
		}
	});
	$('#zhu').on('click', '.buy', function () {
		var a = $('#zhu button').index(this);
		if (主食[a].购买按钮 == 'buy') {
			var zhu_原价 = 主食[a].价格[0].原价;
			var zhu_特价 = 主食[a].价格[0].特价;
			window.onload = chenggong2();
			购买2.push({
				'name': 主食[a].name,
				'img': 主食[a].img,
				'值': '1',
				'详情': 主食[a].详情,
				'单价': Number(zhu_原价 - zhu_特价),
			});
			$("#zhu .gmcg").eq(a).html("<a href='JavaScript:;' class='yigoumai'>已添加到[购物车]</a>");
			$("#zhu button").eq(a).prop("class", "yidianji");
			主食[a].购买按钮 = "yidianji";
			主食[a].购买返回 = "<a href='JavaScript:;' class='yigoumai'>已添加到[购物车]</a>";
			goumaijieguo = 主食[a].name + " 可在 [购物车] 内进行付款";
			window.onload = chenggong2();
			window.onload = xsgm();
		} else {
			goumaijieguo = 主食[a].name + " 已经在购物车了";
			chenggong2();
			$("#zhu button").eq(a).prop("class", "yidianji");
		}
	})
	$('#yan').on('click', '.buy', function () {
		var a = $('#yan button').index(this);
		if (香烟[a].购买按钮 = 'buy') {
			var yan_原价 = 香烟[a].价格[0].原价;
			var yan_特价 = 香烟[a].价格[0].特价;
			购买2.push({
				'name': 香烟[a].name,
				'img': 香烟[a].img,
				'值': '1',
				'详情': 香烟[a].详情,
				'单价': Number(yan_原价 - yan_特价),
			});
			$("#yan .gmcg").eq(a).html("<a href='JavaScript:;' class='yigoumai'>已添加到[购物车]</a>");
			$("#yan button").eq(a).prop("class", "yidianji");
			香烟[a].购买按钮 = "yidianji";
			香烟[a].购买返回 = "<a href='JavaScript:;' class='yigoumai'>已添加到[购物车]</a>";
			goumaijieguo = 香烟[a].name + " 可在 [购物车] 内进行付款";
			window.onload = chenggong2();
			window.onload = xsgm();
		} else {
			goumaijieguo = 香烟[a].name + " 已经在购物车了";
			chenggong2();
			$("#yan button").eq(a).prop("class", "yidianji");
		}
	})
	$('#jiu').on('click', '.buy', function () {
		var a = $('#jiu button').index(this);
		if (酒水[a].购买按钮 == 'buy') {
			var jiu_原价 = 酒水[a].价格[0].原价;
			var jiu_特价 = 酒水[a].价格[0].特价;
			购买2.push({
				'name': 酒水[a].name,
				'img': 酒水[a].img,
				'值': '1',
				'详情': 酒水[a].详情,
				'单价': Number(jiu_原价 - jiu_特价),
			});
			$("#jiu .gmcg").eq(a).html("<a href='JavaScript:;' class='yigoumai'>已添加到[购物车]</a>");
			$("#jiu button").eq(a).prop("class", "yidianji");
			酒水[a].购买按钮 = "yidianji";
			酒水[a].购买返回 = "<a href='JavaScript:;' class='yigoumai'>已添加到[购物车]</a>";
			goumaijieguo = 酒水[a].name + " 可在 [购物车] 内进行付款";
			window.onload = chenggong2();
			window.onload = xsgm();
		} else {
			goumaijieguo = 酒水[a].name + " 已经在购物车了";
			chenggong2();
			$("#jiu button").eq(a).prop("class", "yidianji");
		}
	})
	$(document).on('click', '.neirong2 .subtract', function () {
		var a = $('.subtract').index(this);
		var num = $(this).siblings(".text").val();
		num--; //商品数量
		num = parseInt(num);
		if (num < 1) {
			num = 1;
			购买2[a].值 = Number(num);
			$('.total_price').eq(a).text('单独购买: ' + num * 购买2[a].单价);
		} else {
			$(this).siblings(".text").val(num);
			购买2[a].值 = Number(num);
			$('.total_price').eq(a).text('单独购买: ' + num * 购买2[a].单价);
		}
	})
	$(document).on("input", ".neirong2 .text", function () {
		var a = $('.text').index(this);
		var num = $(".neirong2 .text").eq(a).val()
		var nums = $(".text").eq(a).val();
		num = parseInt(num);
		let numpd = /^-?\d+$/;
		if (numpd.test(nums)) {
			if (nums.length > 5) {
				$(".neirong2 .tishi").eq(a).css("color", "rgba(255, 0, 0, 0.673)");
				$(".neirong2 .tishi").eq(a).html("不能大于五位数");
				$(".neirong2 .text").eq(a).css("border", "2px solid rgba(255, 0, 0, 0.673)");
			} else {
				if (nums == "0") {
					$(".neirong2 .tishi").eq(a).css("color", "rgba(255, 0, 0, 0.673)");
					$(".neirong2 .tishi").eq(a).html("不能为0");
					$(".neirong2 .text").eq(a).css("border", "2px solid rgba(255, 0, 0, 0.673)");
				} else {
					$(".neirong2 .tishi").eq(a).css("color", "#41d246ae");
					$(".neirong2 .tishi").eq(a).html("格式正确");
					$(".neirong2 .text").eq(a).css("border", "2px solid #41d246ae");
				}
			}
		} else {
			$(".neirong2 .tishi").eq(a).css("color", "rgba(255, 0, 0, 0.673)");
			$(".neirong2 .tishi").eq(a).html("请输入数字");
			$(".neirong2 .text").eq(a).css("border", "2px solid rgba(255, 0, 0, 0.673)");
		}
	})
	$(document).on('change', '.neirong2 .text', function () {
		var a = $('.text').index(this);
		var num = document.getElementsByClassName("text")[a].value;
		var nums = $(".text").eq(a).val();
		num = parseInt(num);
		let numpd = /^-?\d+$/;
		if (numpd.test(nums)) {
			if (num < 1) {
				num = 1;
				购买2[a].值 = Number(num);
				num = document.getElementsByClassName("text")[a].value = 1;
			} else if (num > 99999) {
				document.getElementsByClassName("text")[a].value = 购买2[a].值;
			} else {
				购买2[a].值 = Number(num);
			}
		} else {
			document.getElementsByClassName("text")[a].value = 购买2[a].值;
			$(".neirong2 .tishi").eq(a).css("color", "#41d246ae");
			$(".neirong2 .tishi").eq(a).html("格式正确");
			$(".neirong2 .text").eq(a).css("border", "2px solid #41d246ae");
		}
		$('.total_price').eq(a).text('单独购买: ' + Number(购买2[a].单价 * 购买2[a].值));
	})
	$(document).on('click', '.neirong2 .plus', function () {
		var a = $('.plus').index(this);
		var num = $(this).siblings(".text").val();
		num++; //商品数量
		num = parseInt(num);
		if (num > 99999) {
			document.getElementsByClassName("text")[a].value = 购买2[a].值;
		} else {
			$(this).siblings(".text").val(num);
			购买2[a].值 = Number(num);
			$('.total_price').eq(a).text('单独购买: ' + num * 购买2[a].单价);
		}
	})
	$(document).on("click", ".caidan", function () {
		window.onload = hot_cai();
		window.onload = cool_cai();
		window.onload = zhu_cai();
		window.onload = tang_cai();
		window.onload = yan_cai();
		window.onload = jiu_cai();
	})
	// $("#goumai .buy2").draggable();
	// // $(".neirong .menu").draggable();
})

function jiezhang() {
	total = 0;
	for (var a = 0; a < 购买2.length; a++) {
		total += Number(购买2[a].单价 * 购买2[a].值);
		// total = $("#goumai .check").length;
	}
	document.getElementById('gm').innerHTML = "结算 ¥ " + total;
}

$(document).on('click', '.splice', function () {
	var a = $('.splice').index(this);
	caiming = 购买2[a].name;
	classxuanze = "yishanchu";
	htmlneirong = "购物车内已删除";
	window.onload = forxunhuan();
	购买2.splice(a, 1);
	window.onload = xsgm();
	goumaijieguo = "您已成功删除: " + caiming;
	window.onload = chenggong2();
})

$(document).on("click", ".qxgm", function () {
	goumaijieguo = "暂不支持网上 [取消购买],需找前台退款,望谅解!";
	window.onload = chenggong2();
})